﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_adding_a_relation_between_different_types
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class GuiPerson
        {
            public String Id { get; set; }
            public int Age { get; set; }
        }
        public class DomainPerson
        {
            public int Id { get; set; }
            public String Age { get; set; }
        }

        public When_adding_a_relation_between_different_types()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_get_exception_when_converter_is_not_added()
        {
            Assert.Throws<GlueException>(() =>
                                             mapping.Relate(master => master.Id, t => t.Id)
                );
        }
        
        [Fact]
        public void Should_accept_if_converter_exists()
        {
            mapping.AddConverter(Converting.BetweenIntAndString());
            mapping.Relate(master => master.Id, t => t.Id);
        }

        [Fact]
        public void Should_accept_bidirectional_if_converter_exists()
        {
            mapping.AddConverter(Converting.BetweenIntAndString());
            mapping.Relate(master => master.Age, t => t.Age);
        }

    }
}